<!--  -->
<template>
  <div>
    <el-form :model="form" size="small" label-width="100px">
      <el-form-item label="科目">
        <el-radio-group v-model="form.mainSub">
          <el-radio label="历史">历史</el-radio>
          <el-radio label="物理">物理</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="分数">
        <el-input v-model="form.num" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">确定</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { updateUser } from '@/api/user/user'
export default {
  data() {
    return {
      form: {
        mainSub: '',
        num: ''
      }
    }
  },
  mounted() {
    const user = JSON.parse(localStorage.getItem('user'))
    if (user) {
      this.form.mainSub = user.mainSub
      this.form.num = user.num
    }
    // console.log(user)
  },
  methods: {
    onSubmit() {
      const user = JSON.parse(localStorage.getItem('user'))
      user.mainSub = this.form.mainSub
      user.num = this.form.num
      const param = {
        id: user.id,
        mainSub: this.form.mainSub,
        num: this.form.num
      }
      // console.log(param)
      updateUser(param).then(res => {
        this.$msg.success('修改成功')
        localStorage.setItem('user', JSON.stringify(user))
      })
    }
  }
}
</script>

<style scoped></style>
